package com.lb.api;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import static com.lb.base.constants.BaseConstants.PATH_PATTERN_ALL;


/**
 * API 配置类
 *
 * @author xiemingzhi
 * @since 1.0
 */
@Configuration
@ComponentScan({"com.lb.api"})
public class ApiConfiguration implements WebMvcConfigurer {

    private final ApiLogInterceptorAdvice apiLogInterceptorAdvice;

    public ApiConfiguration(
            ApiLogInterceptorAdvice apiLogInterceptorAdvice) {
        this.apiLogInterceptorAdvice = apiLogInterceptorAdvice;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        ApiTraceInterceptor apiTraceInterceptor = new ApiTraceInterceptor();
        registry.addInterceptor(apiTraceInterceptor).addPathPatterns(PATH_PATTERN_ALL).order(apiTraceInterceptor.getOrder());
        registry.addInterceptor(apiLogInterceptorAdvice).addPathPatterns(PATH_PATTERN_ALL).order(apiLogInterceptorAdvice.getOrder());
    }
}
